# ifndef __ORCA_SNIFF_H__
# define __ORCA_SNIFF_H__

#include "orca.h"

typedef struct orca_s {
    char *recv_buffer;
}orca_t;

char    msg [MAX_MSG_SIZE];
orca_t recvBuf; 

/* get the protocol in 
 * Network Byte Order
 */
int get_proto_field (int proto_field)
{
    int proto = ((proto_field >> 8)&0xff) + 
	((proto_field << 8)&0xff00);
    return proto;	
}

void show_arp_packet (struct arphdr *arp_header)
{
    orca_arp_t hdr_arphdr;
    hdr_arphdr.orca_arphdr = arp_header;

    printf ("-Operation type : ");
    switch (htons(hdr_arphdr.orca_arphdr->ar_op))
    {
		case (ARPOP_REQUEST):
	    	printf ("ARP request (0x0%2.2X) \n", 
				hdr_arphdr.orca_arphdr->ar_op);
	    	break;
		case (ARPOP_REPLY):
	    	printf ("ARP reply (0x0%2.2X) \n", 
				hdr_arphdr.orca_arphdr->ar_op);
			break;
	case (ARPOP_RREQUEST):
	    printf ("RARP request (0x0%2.2X) \n", 
			hdr_arphdr.orca_arphdr->ar_op);
			break;
	case (ARPOP_RREPLY):
	    printf ("RARP reply (0x0%2.2X) \n", 
			hdr_arphdr.orca_arphdr->ar_op);
	    break;
	case (ARPOP_InREQUEST):
	    printf ("InARP request (0x0%2.2X) \n", hdr_arphdr.orca_arphdr->ar_op);
	    break;
	case (ARPOP_InREPLY):
	    printf ("InARP reply (0x0%2.2X) \n", hdr_arphdr.orca_arphdr->ar_op);
	    break;
	case (ARPOP_NAK):
	    printf ("(ATM)ARP NAK (0x0%2.2X) \n", hdr_arphdr.orca_arphdr->ar_op);
	    break;
	default:
	    printf ("Unknown Protocol (0x0%2.2X) \n", hdr_arphdr.orca_arphdr->ar_op);
	    break;
    }

    printf ("-Hardware type : ");
    switch (htons(hdr_arphdr.orca_arphdr->ar_hrd))
    {	
	case ARPHRD_NETROM:   
               /* from KA9Q: NET/ROM pseudo    */
	    printf ("NET/ROM pseudo\n");
	    break;
	case ARPHRD_ETHER:    
               /* Ethernet 10Mbps              */
	    printf ("Ethernet 10Mbps\n");
	    break;
	case ARPHRD_EETHER:   
               /* Experimental Ethernet        */
	    printf ("Experimental Ethernet\n");
	    break;
	case ARPHRD_AX25:     
               /* AX.25 Level 2                */
	    printf ("AX.25 Level 2\n");
	    break;
	case ARPHRD_PRONET:   
               /* PROnet token ring            */
	    printf ("PROnet token ring\n");
	    break;
	case ARPHRD_CHAOS:    
               /* Chaosnet                     */
	    printf ("Chaosnet\n");
	    break;
	case ARPHRD_IEEE802:  
               /* IEEE 802.2 Ethernet/TR/TB    */
	    printf ("IEEE 802.2 Ethernet/TR/TB\n");
	    break;
	case ARPHRD_ARCNET:   
               /* ARCnet                       */
	    printf ("ARCnet\n");
	    break;
	case ARPHRD_APPLETLK: 
               /* APPLEtalk                    */
	    printf ("APPLEtalk\n");
	    break;
	case ARPHRD_DLCI:   
               /* Frame Relay DLCI             */
	    printf ("Frame Relay DLCI\n");
	    break;
	case ARPHRD_ATM:        
               /* ATM                          */
	    printf ("ATM\n");
	    break;
	case ARPHRD_METRICOM:   
              /* Metricom STRIP (new IANA id) */
	    printf ("Metricom STRIP (new IANA id)\n");
	    break;
	case ARPHRD_IEEE1394: 
              /* IEEE 1394 IPv4 - RFC 2734    */
	    printf ("IEEE 1394 IPv4\n");
	    break;
	case ARPHRD_EUI64:    
              /* EUI-64                       */
	    printf ("EUI-64\n");
	    break;
	case ARPHRD_INFINIBAND:
              /* InfiniBand                   */
	    printf ("InfiniBand\n");
	    break;
	default:
	    break;
    } 
}

void show_eth_frame (struct ethhdr *eth_header)
{
    orca_eth_t hdr_eth;
    hdr_eth.orca_eth = eth_header;

    hdr_eth.proto = get_proto_field (hdr_eth.orca_eth->h_proto);

    printf (" Destination Mac address: %2.2x.%2.2x.%2.2x.%2.2x.%2.2x.%2.2x\n",
        hdr_eth.orca_eth->h_dest[0], hdr_eth.orca_eth->h_dest[1], 
	hdr_eth.orca_eth->h_dest[2], hdr_eth.orca_eth->h_dest[3], 
	hdr_eth.orca_eth->h_dest[4], hdr_eth.orca_eth->h_dest[5]);

    printf (" Source Mac address: %2.2x.%2.2x.%2.2x.%2.2x.%2.2x.%2.2x\n",
        hdr_eth.orca_eth->h_source[0], hdr_eth.orca_eth->h_source[1], 
	hdr_eth.orca_eth->h_source[2], hdr_eth.orca_eth->h_source[3], 
	hdr_eth.orca_eth->h_source[4], hdr_eth.orca_eth->h_source[5]);

    switch (hdr_eth.proto)
    {
        case ETH_P_LOOP:
            /* Ethernet Loopback packet     */
	    printf ("Ethernet Loop\n");
	    break;       	
	case ETH_P_PUP:
	    /* Xerox PUP packet             */
	    printf ("Xerox PUP packet\n");
	    break;	
	case ETH_P_PUPAT:
	    /* Xerox PUP Addr Trans packet  */
	    printf ("Xerox PUP Addr Trans packet\n");
	    break;	
	case ETH_P_IP:
	    /* Internet Protocol packet     */
	    printf ("Internet Protocol packet (IPv4)\n");
	    break;
	case ETH_P_X25:
            /* CCITT X.25                   */
	    printf ("CCITT X.25\n");
	    break;	
	case ETH_P_ARP:
	    /* Address Resolution packet    */
	    printf ("Address Resolution packet (ARP)\n");
	    show_arp_packet ((struct arphdr*) (msg + sizeof (struct ethhdr)));
	    break;	
	case ETH_P_BPQ:
	    /* G8BPQ AX.25 Ethernet Packet  [ NOT AN OFFICIALLY REGISTERED ID ] */
	    printf (" G8BPQ AX.25 Ethernet Packet\n");
	    break;
	case ETH_P_IEEEPUP:
	    /* Xerox IEEE802.3 PUP packet */
	    printf ("Xerox IEEE802.3 PUP packet\n");
	    break;
	case ETH_P_IEEEPUPAT:
	    /* Xerox IEEE802.3 PUP Addr Trans packet */
	    printf ("Xerox IEEE802.3 PUP Addr Trans packet\n");
	    break;
	case ETH_P_DEC:
            /* DEC Assigned proto           */
	    printf ("DEC Assigned proto\n");
	    break;	
	case ETH_P_DNA_DL:
	    /* DEC DNA Dump/Load            */
	    printf ("DEC DNA Dump/Load\n");
	    break;	
	case ETH_P_DNA_RC:
	    /* DEC DNA Remote Console       */
	    printf ("DEC DNA Remote Console\n");
	    break;	
	case ETH_P_DNA_RT:
	    /* DEC DNA Routing              */
	    printf ("DEC DNA Routing\n");
	    break;	
	case ETH_P_LAT:
            /* DEC LAT                      */
	    printf ("DEC LAT\n");
	    break;	
	case ETH_P_DIAG:
	    /* DEC Diagnostics              */
	    printf ("DEC Diagnostics\n");
	    break;	
	case ETH_P_CUST:      
            /* DEC Customer use             */
	    printf ("DEC Customer use\n");
	    break;	
	case ETH_P_SCA:    
            /* DEC Systems Comms Arch       */
	    printf ("DEC Systems Comms Arch\n");
	    break;	
	case ETH_P_TEB:
	    /* Trans Ether Bridging         */
	    printf ("Trans Ether Bridging\n");
	    break;	
	case ETH_P_RARP:               
	    /* Reverse Addr Res packet      */
	    printf ("Reverse Addr Res packet (RARP)\n");
	    break;	
	case ETH_P_ATALK:               
	    /* Appletalk DDP                */
	    printf ("Appletalk DDP\n");
	    break;	
	case ETH_P_AARP:                
	    /* Appletalk AARP               */
	    printf ("Appletalk AARP\n");
	case ETH_P_8021Q:               
	    /* 802.1Q VLAN Extended Header  */
	    printf ("802.1Q VLAN Extended Header\n");
	    break;	
	case ETH_P_IPX:                 
	    /* IPX over DIX                 */
	    printf ("IPX over DIX\n");
	    break;	
	case ETH_P_IPV6:                
	    /* IPv6 over bluebook           */
	    printf ("IPv6 over bluebook\n");
	    break;	
	case ETH_P_PAUSE:               
	    /* IEEE Pause frames. See 802.3 31B */
	    printf ("IEEE Pause frames. See 802.3 31B\n");
	    break;	
	case ETH_P_SLOW:                
	    /* Slow Protocol. See 802.3ad 43B */
	    printf ("Slow Protocol. See 802.3ad 43B\n");
	    break;	
	case ETH_P_WCCP:
	    /* Web-cache coordination protocol
             * defined in draft-wilson-wrec-wccp-v2-00.txt */
	    printf ("Web-cache coordination protocol\n");
	    break;	
	case ETH_P_PPP_DISC:
            /* PPPoE discovery messages     */
	    printf ("PPPoE discovery messages\n");
	    break;	
	case ETH_P_PPP_SES:
	    /* PPPoE session messages       */
	    printf ("PPPoE session messages\n");
	    break;	
	case ETH_P_MPLS_UC:
	    /* MPLS Unicast traffic         */
	    printf ("MPLS Unicast traffic\n");
	    break;	
	case ETH_P_MPLS_MC:
	    /* MPLS Multicast traffic       */
	    printf ("MPLS Multicast traffic\n");
	    break;	
	case ETH_P_ATMMPOA:
	    /* MultiProtocol Over ATM       */
	    printf ("MultiProtocol Over ATM \n");
	    break;	
	case ETH_P_ATMFATE:
            /* Frame-based ATM Transport
             * over Ethernet
             */
	    printf ("Frame-based ATM Transport over Ethernet\n");
	    break;	
	case ETH_P_PAE:
	    /* Port Access Entity (IEEE 802.1X) */
	    printf ("Port Access Entity (IEEE 802.1X)\n");
	    break;	
	case ETH_P_AOE:
	    /* ATA over Ethernet            */
	    printf ("ATA over Ethernet\n");
	    break;	
	case ETH_P_TIPC:
            /* TIPC                         */
	    printf ("TIPC\n");
	    break;	
	case ETH_P_1588:                
	    /* IEEE 1588 Timesync */
	    printf ("IEEE 1588 Timesync\n");
	    break;	
	case ETH_P_FCOE:                
	    /* Fibre Channel over Ethernet  */
	    printf ("Fibre Channel over Ethernet\n");
	    break;	
	case ETH_P_FIP:                 
	    /* FCoE Initialization Protocol */
	    printf ("FCoE Initialization Protocol\n");
	    break;	
	case ETH_P_EDSA:                
            /* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
	    printf ("Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ]\n");
	    break;	
	default:
	    printf ("Unregisterd Protocol\n");
	    break;
    }	

}

void show_ip_packet (struct ip *ip_header)
{
    orca_ip_t *orca_iphdr;
    orca_iphdr->orca_iphdr = ip_header;
}

void show_icmp_packet (struct icmphdr *icmp_header)
{
    orca_icmp_t *orca_icmphdr;
    orca_icmphdr->orca_icmphdr = icmp_header;
}

void show_tcp_packet (struct tcphdr *tcp_header)
{
    orca_tcp_t *orca_tcphdr;
    orca_tcphdr->orca_tcphdr = tcp_header;
}

void show_udp_packet (struct udphdr *udp_header)
{
    orca_udp_t *orca_udphdr;
    orca_udphdr->orca_udphdr = udp_header;
}

# endif /* __ORCA_SNIFF_H__ */
